Skip to content

Commit

Permalink
Update to my latest plugin framework
Browse files Browse the repository at this point in the history
  • Loading branch information
hexosse committed Oct 1, 2017
1 parent a1cbe3e commit 034dcf5
Show file tree
Hide file tree
Showing 22 changed files with 861 additions and 675 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ All commands have a full tab completion with a detailed help.
#### API:
As it is designed as an API, you can add RandomItems to your plugin using maven

```
```Maven
<repositories>
<repository>
<id>hexosse-repo</id>
Expand All @@ -62,7 +62,7 @@ As it is designed as an API, you can add RandomItems to your plugin using maven
</repositories>
```

```
```Maven
<dependencies>
<dependency>
<groupId>com.github.hexocraft</groupId>
Expand All @@ -74,9 +74,3 @@ As it is designed as an API, you can add RandomItems to your plugin using maven
```

The API can be found in RandomItemsApi class.
<br>
<br>


#### Ressources:
Releases : https://github.com/hexocraft/RandomItems/releases
70 changes: 18 additions & 52 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<groupId>com.github.hexocraft</groupId>
<artifactId>random-items</artifactId>
<name>RandomItems</name>
<version>1.0.3</version>
<version>2.0.0</version>
<packaging>jar</packaging>
<description>.</description>
<description>Get random items from a pool of weighted items.</description>
<url>https://github.com/HexoCraft/${project.name}</url>


Expand Down Expand Up @@ -55,7 +55,7 @@
<!-- Propriétés du projet -->
<properties>
<jdk.version>1.7</jdk.version>
<bukkit.version>1.11-R0.1-SNAPSHOT</bukkit.version>
<bukkit.version>1.12.2-R0.1-SNAPSHOT</bukkit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<github.global.server>github</github.global.server>
</properties>
Expand Down Expand Up @@ -145,12 +145,18 @@
<artifactId>plugin</artifactId>
<version>[1.0.0, )</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.github.hexocraftapi</groupId>
<artifactId>lights</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Language Utils -->
<dependency>
<groupId>com.meowj</groupId>
<artifactId>LangUtils</artifactId>
<version>1.6.3</version>
<version>1.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -189,55 +195,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<version>3.7.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<optimize>true</optimize>
</configuration>
</plugin>

<!-- maven-source-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- maven-javadoc-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>
<dependencySourceInclude>com.github.hexocraftapi:**</dependencySourceInclude>
</dependencySourceIncludes>
</configuration>
</plugin>

<!-- maven-shade-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -246,13 +216,9 @@
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.objecthunter.exp4j</pattern>
<shadedPattern>${project.groupId}.random.items.api.exp4j</shadedPattern>
</relocation>
<relocation>
<pattern>com.github.hexocraftapi</pattern>
<shadedPattern>${project.groupId}.random.items.api</shadedPattern>
<shadedPattern>${project.groupId}.${project.artifactId}.api</shadedPattern>
</relocation>
</relocations>
<minimizeJar>false</minimizeJar>
Expand All @@ -271,11 +237,11 @@
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<API-Name>${project.name}</API-Name>
<API-Version>${project.version}</API-Version>
<Name>${project.name}</Name>
<Version>${project.version}</Version>
</manifestEntries>
</archive>
<!-- <outputDirectory>../../Serveurs/Tests/plugins</outputDirectory> -->
<!-- <outputDirectory>../../ServerTest/plugins</outputDirectory> -->
</configuration>
</plugin>

Expand All @@ -302,7 +268,7 @@
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<!-- git commit predifined -->
<!-- git commit message -->
<message>Maven artifacts for ${project.name} ${project.version}</message>
<!-- disable webpage processing -->
<noJekyll>true</noJekyll>
Expand All @@ -322,7 +288,7 @@
<!-- github username -->
<repositoryOwner>hexosse</repositoryOwner>
<!-- github OAuth Token -->
<oauth2Token>${env.GITHUB_OAUTH_TOKEN}</oauth2Token>
<!-- <oauth2Token>${env.GITHUB_OAUTH_TOKEN}</oauth2Token> -->
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*/

import com.github.hexocraftapi.util.PlayerUtil;
import com.github.hexocraft.random.items.radomitem.RandomItem;
import com.github.hexocraft.random.items.radomitem.RandomPool;
import com.github.hexocraftapi.util.PlayerUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
* limitations under the License.
*/

import com.github.hexocraftapi.message.Line;
import com.github.hexocraftapi.message.predifined.message.PluginMessage;
import com.github.hexocraftapi.message.predifined.message.PluginTitleMessage;
import com.github.hexocraftapi.plugin.Plugin;
import com.github.hexocraftapi.updater.GitHubUpdater;
import com.github.hexocraft.random.items.command.RiCommands;
import com.github.hexocraft.random.items.configuration.Config;
import com.github.hexocraft.random.items.configuration.Items;
import com.github.hexocraft.random.items.configuration.Messages;
import com.github.hexocraft.random.items.integrations.LanguageUtils;
import com.github.hexocraft.random.items.integrations.langUtilsHooker;
import com.github.hexocraftapi.integration.Hook;
import com.github.hexocraftapi.message.Line;
import com.github.hexocraftapi.message.predifined.message.PluginMessage;
import com.github.hexocraftapi.message.predifined.message.PluginTitleMessage;
import com.github.hexocraftapi.plugin.Plugin;
import com.github.hexocraftapi.updater.BukkitUpdater;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
Expand All @@ -40,7 +41,8 @@ public class RandomItemsPlugin extends Plugin
public static Messages messages = null;
public static Items items = null;

public static LanguageUtils langUtils = null;
/* Plugins */
public static langUtilsHooker langUtils = null;

@Override
public void onEnable()
Expand All @@ -57,20 +59,18 @@ public void onEnable()
registerCommands(new RiCommands(this));

/* LangUtils */
langUtils = new LanguageUtils(this);
langUtils = (langUtilsHooker) new Hook(langUtilsHooker.class, "LangUtils", "com.meowj.langutils.LangUtils").get();

/* Enable message */
PluginTitleMessage titleMessage = new PluginTitleMessage(this, "ServerEvents is enable ...", ChatColor.YELLOW);
if(langUtils.enabled()) titleMessage.add("Integration with " + ChatColor.YELLOW + langUtils.getName());
PluginTitleMessage titleMessage = new PluginTitleMessage(this, "RandomItems is enable ...", ChatColor.YELLOW);
if(langUtils != null) titleMessage.add("Integration with " + ChatColor.YELLOW + langUtils.get().getName());
titleMessage.send(Bukkit.getConsoleSender());

/* Updater */
if(config.useUpdater)
runUpdater(getServer().getConsoleSender(), 20 * 10);
/* Updater */
runUpdater(getServer().getConsoleSender(), 20 * 10);

/* Metrics */
if(config.useMetrics)
runMetrics(20 * 2);
/* Metrics */
runMetrics(20 * 2);
}

@Override
Expand All @@ -84,11 +84,13 @@ public void onDisable()

public void runUpdater(final CommandSender sender, int delay)
{
super.runUpdater(new GitHubUpdater(this, "HexoCraft/RandomItems"), sender, delay);
if(config.useUpdater)
super.runUpdater(new BukkitUpdater(this, "278925"), sender, config.downloadUpdate ,delay);
}

private void runMetrics(int delay)
{
super.RunMetrics(delay);
if(config.useMetrics)
super.RunMetrics(delay);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* limitations under the License.
*/

import com.github.hexocraftapi.command.CommandInfo;
import com.github.hexocraftapi.command.type.ArgType;
import com.github.hexocraft.random.items.RandomItemsApi;
import com.github.hexocraft.random.items.RandomItemsPlugin;
import com.github.hexocraft.random.items.radomitem.RandomPool;
import com.github.hexocraftapi.command.CommandInfo;
import com.github.hexocraftapi.command.type.ArgType;
import com.google.common.collect.ImmutableList;
import org.bukkit.util.StringUtil;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.github.hexocraft.random.items.command;

/*
* Copyright 2017 hexosse
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.github.hexocraft.random.items.RandomItemsApi;
import com.github.hexocraft.random.items.RandomItemsPlugin;
import com.github.hexocraft.random.items.command.ArgType.ArgTypeRandomPool;
import com.github.hexocraft.random.items.configuration.Permissions;
import com.github.hexocraftapi.command.Command;
import com.github.hexocraftapi.command.CommandArgument;
import com.github.hexocraftapi.command.CommandInfo;
import com.github.hexocraftapi.command.type.ArgTypeInteger;
import com.github.hexocraftapi.command.type.ArgTypeString;
import com.github.hexocraftapi.message.predifined.message.ErrorPrefixedMessage;
import com.github.hexocraftapi.message.predifined.message.SimplePrefixedMessage;
import com.github.hexocraftapi.util.PlayerUtil;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import static com.github.hexocraft.random.items.command.RiCommands.commandMessageColor;
import static com.github.hexocraft.random.items.command.RiCommands.prefix;

/**
* @author <b>Hexosse</b> (<a href="https://github.com/hexosse">on GitHub</a>))
*/
public class RiCommandAdd extends Command<RandomItemsPlugin>
{
public RiCommandAdd(RandomItemsPlugin plugin)
{
super("add", plugin);
this.setAliases(Lists.newArrayList("a"));
this.setDescription(StringUtils.join(plugin.messages.cAdd,"\n"));
this.setPermission(Permissions.CREATE.toString());

this.addArgument(new CommandArgument<String>("name", ArgTypeRandomPool.get(), true, true, plugin.messages.cAddArgName));
this.addArgument(new CommandArgument<Integer>("weight", ArgTypeInteger.get(), true, true, plugin.messages.cAddArgWeight));
this.addArgument(new CommandArgument<String>("Description", ArgTypeString.get(), false, false, plugin.messages.cAddArgDesc));
}

/**
* 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)
{
String name = commandInfo.getNamedArg("name");
Integer weight = Integer.parseInt(commandInfo.getNamedArg("weight"));
String description = commandInfo.getNamedArg("Description") != null ? commandInfo.getNamedArg("Description") : null;

//
if(!RandomItemsApi.contains(name)) return false;

// Get item in hand
Player player = commandInfo.getPlayer();
ItemStack itemStack = PlayerUtil.getItemInHand(player);

//
if(RandomItemsApi.add(name, description, itemStack, weight) != null){
SimplePrefixedMessage.toPlayer(commandInfo.getPlayer(), prefix, plugin.messages.sAdd.replace("{NAME}",name), commandMessageColor);
RandomItemsApi.save();
return true;
}
else {
ErrorPrefixedMessage.toPlayer(commandInfo.getPlayer(), prefix, plugin.messages.eAdd.replace("{NAME}",name));
return false;
}
}
}
Loading

0 comments on commit 034dcf5

Please sign in to comment.