Skip to content

Commit

Permalink
Update template to GameBox v3
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Mar 20, 2020
1 parent 2f5c18f commit f08377b
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 84 deletions.
69 changes: 56 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,55 @@
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>me.nikl.gamebox.games</groupId> <!-- Todo -->
<artifactId>GameTemplate</artifactId> <!-- Todo -->
<version>1.0.0</version>
<groupId>me.nikl.gamebox.games</groupId>
<artifactId>template</artifactId>
<name>TemplateGame</name>
<version>3.0.0</version>
<packaging>jar</packaging>
<description>Small template to help you write your own games</description>

<scm>
<url>https://github.com/NiklasEi/cookieclicker-for-gamebox</url>
<connection>[email protected]:NiklasEi/cookieclicker-for-gamebox.git</connection>
</scm>

<build>
<defaultGoal>clean package</defaultGoal>
<finalName>${project.name}</finalName>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create-timestamp</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
Expand All @@ -24,26 +70,23 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.14.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- GameBox -->
<dependency>
<groupId>me.nikl.gamebox</groupId>
<artifactId>GameBox</artifactId>
<version>2.0.0-BETA</version>
<groupId>me.nikl</groupId>
<artifactId>gamebox</artifactId>
<version>${gamebox.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<defaultGoal>clean package</defaultGoal>
<finalName>${project.artifactId}</finalName>
</build>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<gamebox.version>3.0.0-beta.2</gamebox.version>
</properties>
</project>
</project>
37 changes: 37 additions & 0 deletions src/main/java/me/nikl/gamebox/games/GameTemplateModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.nikl.gamebox.games;

import me.nikl.gamebox.games.templategame.Template;
import me.nikl.gamebox.module.GameBoxModule;

/**
* Template module for GameBox
*
* @author Niklas Eicker
*/
public class GameTemplateModule extends GameBoxModule {
public static final String gameID = "templategame";

@Override
public void onEnable(){
/*
All resources for a specific module have to be in the folder 'games/moduleID/'
This folder MUST contain a 'config.yml'
All subfolders are also copied to the gameBox folder and can be used for game
specific additional resources
All language files belong in 'language/moduleID/'
This folder MUST contain a 'lang_en.yml' which is used for default messages
*/

// As this module whats to add a game, we can register it here
// The last Strings are subcommands. Our template game could be opened with:
// '/gb templategame'
// '/gb test1' and '/gb test2'
registerGame(gameID, Template.class, "test1", "test2");
}

@Override
public void onDisable(){
// clean up your own resources
// Nothing to do atm
}
}
40 changes: 0 additions & 40 deletions src/main/java/me/nikl/gamebox/games/GameTemplatePlugin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import me.nikl.gamebox.GameBox;
import me.nikl.gamebox.game.Game;
import me.nikl.gamebox.game.GameSettings;
import me.nikl.gamebox.games.GameTemplatePlugin;
import me.nikl.gamebox.games.GameTemplateModule;

/**
* @author Niklas Eicker
*
* Main class of the game. The path to this class has to be passed to the module (@see {@link GameTemplatePlugin})
* Main class of the game. This class has to be passed to the module (@see {@link GameTemplateModule})
*/
public class Template extends Game {

public Template(GameBox gameBox){
super(gameBox, GameTemplatePlugin.gameID);
super(gameBox, GameTemplateModule.gameID);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.nikl.gamebox.games.templategame;

import me.nikl.gamebox.data.toplist.SaveType;
import me.nikl.gamebox.game.manager.GameManager;
import me.nikl.gamebox.game.manager.EasyManager;
import me.nikl.gamebox.game.rules.GameRule;
import me.nikl.gamebox.game.rules.GameRuleRewards;
import me.nikl.gamebox.games.GameTemplatePlugin;
import me.nikl.gamebox.games.GameTemplateModule;
import me.nikl.gamebox.game.exceptions.GameStartException;
import me.nikl.gamebox.nms.NmsFactory;
import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -22,7 +22,7 @@
*
* This example game simply prints a message when you click while you are in-game
*/
public class TemplateManager implements GameManager {
public class TemplateManager extends EasyManager {
private Template template;
private HashMap<UUID, String> players = new HashMap<>();
private HashMap<UUID, Integer> clicks = new HashMap<>();
Expand All @@ -39,7 +39,6 @@ public void onInventoryClick(InventoryClickEvent inventoryClickEvent) {
addClick(uuid);
NmsFactory.getNmsUtility().updateInventoryTitle((Player)inventoryClickEvent.getWhoClicked()
,((TemplateLanguage)template.getGameLang()).GAME_TITLE.replace("%clicks%", String.valueOf(clicks.get(uuid))));
return;
}

private void addClick(UUID uniqueId) {
Expand All @@ -49,7 +48,6 @@ private void addClick(UUID uniqueId) {
@Override
public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) {
removeFromGame(inventoryCloseEvent.getPlayer().getUniqueId());
return;
}

@Override
Expand All @@ -70,7 +68,7 @@ public void startGame(Player[] players, boolean playSounds, String... strings) t
@Override
public void removeFromGame(UUID uuid) {
if(rules.get(players.get(uuid)).isSaveStats())
template.getGameBox().getDataBase().addStatistics(uuid, GameTemplatePlugin.gameID
template.getGameBox().getDataBase().addStatistics(uuid, GameTemplateModule.gameID
, rules.get(players.get(uuid)).getKey(), clicks.get(uuid)
, rules.get(players.get(uuid)).getSaveType());
players.remove(uuid);
Expand Down Expand Up @@ -100,13 +98,4 @@ and save them in a class extending GameRule.
public Map<String, ? extends GameRule> getGameRules() {
return rules;
}

/*
This method can be ignored and does not have to return anything.
It has the purpose to be able to use an InventoryHolder based gui system for the games.
*/
@Override
public Inventory getInventory() {
return null;
}
}
13 changes: 7 additions & 6 deletions src/main/resources/games/templategame/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ economy:

gameBox:
mainButton:
# define the Material and data for the button (format: 'material:data')
materialData: "357"
# define the Material for the main button
materialData: "GRASS"
# display name of the button
# ToDo: name
displayName: "&3Template"
Expand All @@ -29,10 +29,10 @@ gameBox:
- ""
- "&1Some funny and short description"
- ""
- "&5&o\"blub blub blub...\""
- "&5&o\"bli bla blub...\""
gameButtons:
game1:
materialData: "5:2"
materialData: "GRASS"
# ToDo: name
displayName: "&aTemplate"
lore:
Expand All @@ -57,10 +57,11 @@ gameBox:
# use the same key as the game you want to display the top list for
# for that button 'saveStats' must be true (see above)
game1:
materialData: "6:2"
materialData: "GRASS"
# ToDo: name
displayName: "&6Template &c&lTop list"
slot: 24
glow: true
# inventory title of the top list (%player% and %game%)
# ToDo: name
inventoryTitle: ' &6Template &rTop List'
Expand All @@ -70,4 +71,4 @@ gameBox:
skullLore:
- ''
- '&6Rank:&1 %rank%'
- '&6Score:&1 %score%'
- '&6Score:&1 %score%'
2 changes: 1 addition & 1 deletion src/main/resources/language/templategame/lang_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ name: "&1TemplateGame&r"
gameHelp:
- '&1&lDescribe your game here...'
- ''
- '&1&lClick to get points'
- '&1&lClick to get points'
10 changes: 10 additions & 0 deletions src/main/resources/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: ${project.artifactId}
version: ${project.version}
authors: ["Niklas Eicker"]
name: ${project.name}
description: ${project.description}
sourceUrl: ${project.scm.url}
updatedAt: !!java.lang.Long ${timestamp}
dependencies:
- id: gamebox
versionConstrain: ">= ${gamebox.version}"
6 changes: 0 additions & 6 deletions src/main/resources/plugin.yml

This file was deleted.

0 comments on commit f08377b

Please sign in to comment.