Skip to content

Commit

Permalink
Merge pull request #6 from NiklasEi/gamebox-3
Browse files Browse the repository at this point in the history
Gamebox v3
  • Loading branch information
NiklasEi authored Apr 4, 2020
2 parents 403b12d + 5a295d6 commit 2e35558
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 175 deletions.
77 changes: 63 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,64 @@
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</groupId>
<groupId>me.nikl.gamebox.games</groupId>
<artifactId>logicpuzzles</artifactId>
<version>2.1.0</version>
<name>LogicPuzzles</name>
<packaging>jar</packaging>
<version>3.0.0-beta</version>
<description>Spend some time with brain teasers</description>

<distributionManagement>
<repository>
<id>nikl-repo</id>
<url>http://repo.nikl.me/artifactory/public</url>
</repository>
</distributionManagement>

<scm>
<url>https://github.com/NiklasEi/logic-puzzles-for-gamebox</url>
<connection>git@github.com:NiklasEi/logic-puzzles-for-gamebox.git</connection>
</scm>

<build>
<defaultGoal>clean package</defaultGoal>
<finalName>${project.name}</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<directory>target</directory>
<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 @@ -15,36 +70,30 @@
</repository>
<repository>
<id>nikl-repo</id>
<url>https://repo.nikl.me/artifactory/repositories</url>
<url>http://repo.nikl.me/artifactory/public</url>
</repository>
</repositories>

<dependencies>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.14.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- GameBox -->
<dependency>
<groupId>me.nikl</groupId>
<artifactId>gamebox-core</artifactId>
<version>2.1.4</version>
<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>
22 changes: 22 additions & 0 deletions src/main/java/me/nikl/logicpuzzles/ExtendedInventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.nikl.logicpuzzles;

import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class ExtendedInventory {
private Inventory upperInventory;
private Inventory lowerInventory;

public ExtendedInventory(Inventory upperInventory, Inventory lowerInventory) {
this.upperInventory = upperInventory;
this.lowerInventory = lowerInventory;
}

public void setItem(int slot, ItemStack item) {
if (slot >= upperInventory.getSize()) {
lowerInventory.setItem(slot - upperInventory.getSize() + 9, item);
} else {
upperInventory.setItem(slot, item);
}
}
}
31 changes: 11 additions & 20 deletions src/main/java/me/nikl/logicpuzzles/LogicPuzzles.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
package me.nikl.logicpuzzles;

import me.nikl.gamebox.GameBox;
import me.nikl.gamebox.Module;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import me.nikl.gamebox.module.GameBoxModule;
import me.nikl.logicpuzzles.sudoku.Sudoku;
import me.nikl.logicpuzzles.threeinarow.ThreeInARow;

/**
* Created by Niklas
*
* Main class of the GameBox game Sudoku
*/
public class LogicPuzzles extends JavaPlugin{
public class LogicPuzzles extends GameBoxModule {
public static final String SUDOKU = "sudoku";
public static final String THREE_IN_A_ROW = "threeinarow";
private GameBox gameBox;

@Override
public void onEnable(){
Plugin plugin = Bukkit.getPluginManager().getPlugin("GameBox");
if(plugin == null || !plugin.isEnabled()){
getLogger().warning(" GameBox was not found! Disabling LogicPuzzles...");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
gameBox = (GameBox) plugin;
new Module(gameBox, SUDOKU
, "me.nikl.logicpuzzles.sudoku.Sudoku"
, this, SUDOKU, "su");
new Module(gameBox, THREE_IN_A_ROW
, "me.nikl.logicpuzzles.threeinarow.ThreeInARow"
, this, THREE_IN_A_ROW, "tiar");
registerGame(SUDOKU, Sudoku.class, "su");
registerGame(THREE_IN_A_ROW, ThreeInARow.class, "tiar");
}

@Override
public void onDisable() {

}
}
3 changes: 1 addition & 2 deletions src/main/java/me/nikl/logicpuzzles/sudoku/Sudoku.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void loadSettings() {
gameSettings.setGameType(GameSettings.GameType.SINGLE_PLAYER);
gameSettings.setGameGuiSize(54);
gameSettings.setHandleClicksOnHotbar(false);
gameSettings.setGameBoxMinimumVersion("2.1.4");
}

@Override
Expand All @@ -39,4 +38,4 @@ public void loadLanguage() {
public void loadGameManager() {
gameManager = new SudokuGameManager(this);
}
}
}
42 changes: 9 additions & 33 deletions src/main/java/me/nikl/logicpuzzles/sudoku/SudokuGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.nikl.gamebox.GameBoxSettings;
import me.nikl.gamebox.nms.NmsFactory;
import me.nikl.gamebox.utility.Sound;
import org.bukkit.Material;
import me.nikl.logicpuzzles.ExtendedInventory;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
Expand All @@ -24,7 +24,8 @@ public class SudokuGame {
private String ruleKey;
private boolean playSounds, wasWon = false;
private SudokuLanguage lang;
private Inventory inventory;
//private Inventory inventory;
private ExtendedInventory inventory;
private Player player;
private Sound won = Sound.VILLAGER_YES, click = Sound.CLICK;
private float volume = 0.5f, pitch= 1f;
Expand All @@ -36,8 +37,6 @@ public class SudokuGame {
private BitSet tips = new BitSet(81);
private ItemStack resetButton;
private String puzzle;
private long lastRestartClick = System.currentTimeMillis() - 100000;
private final int resetButtonSlot = 22;

public SudokuGame(SudokuGameRules rule, Sudoku game, Player player, boolean playSounds, String puzzle, Map<Integer, ItemStack> cover, Map<Integer, ItemStack> tip, Map<Integer, ItemStack> number){
this.game = game;
Expand All @@ -53,20 +52,10 @@ public SudokuGame(SudokuGameRules rule, Sudoku game, Player player, boolean play

// create inventory
String title = lang.GAME_TITLE.replace("%score%", String.valueOf(score));
if(GameBoxSettings.checkInventoryLength && title.length() > 32){
title = "Title is too long!";
}
this.inventory = game.createInventory(81, title);
Inventory upperInventory = game.createInventory(54, title);
this.inventory = new ExtendedInventory(upperInventory, player.getInventory());
buildStartingGrid();
player.openInventory(inventory);
if(rule.hasRestartButton()) {
resetButton = new ItemStack(Material.LEVER);
ItemMeta meta = resetButton.getItemMeta();
meta.setDisplayName(lang.RESTART_NAME);
meta.setLore(lang.RESTART_LORE);
resetButton.setItemMeta(meta);
player.getInventory().setItem(resetButtonSlot, resetButton);
}
player.openInventory(upperInventory);
}

private void loadNumberTiles(Map<Integer, ItemStack> number) {
Expand All @@ -92,7 +81,7 @@ private void buildStartingGrid() {
char value;
ItemStack tip;
ItemMeta meta;
for(int slot = 0; slot < inventory.getSize(); slot++){
for(int slot = 0; slot < 81; slot++){
x = (slot%9)/3 + 1;
y = (slot/9)/3;
value = puzzle.charAt(slot);
Expand Down Expand Up @@ -154,23 +143,10 @@ private boolean isWon() {
public void onClick(InventoryClickEvent inventoryClickEvent) {
if(inventoryClickEvent.getCurrentItem() == null) return;
if(wasWon) return;
if(inventoryClickEvent.getRawSlot() > 81 && inventoryClickEvent.getSlot() == resetButtonSlot){
long now = System.currentTimeMillis();
game.debug("reset click...");
if(now - lastRestartClick > 1000){
lastRestartClick = now;
} else {
gridNumbers = new int[81];
buildStartingGrid();
if (playSounds) player.playSound(player.getLocation(), Sound.BURP.bukkitSound(), volume, pitch);
lastRestartClick = now - 1000000;
}
return;
}

int slot = inventoryClickEvent.getSlot();
int slot = inventoryClickEvent.getRawSlot();

// if the bit set is set for the slot it is a tip
// if the bit is set for the slot it is a tip
if(tips.get(slot)) return;

int x = (slot%9)/3;
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/me/nikl/logicpuzzles/sudoku/SudokuGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,25 @@ private void loadItems() {
for (int i = 1; i < 10; i++){
if(!game.getConfig().isConfigurationSection("items.grid." + i)){
Bukkit.getConsoleSender().sendMessage(lang.PREFIX + ChatColor.RED + " items.grid." + i + " section missing in config");
cover.put(i, new ItemStack(Material.STAINED_GLASS_PANE, 1));
tip.put(i, new ItemStack(Material.HARD_CLAY, i));
number.put(i, new ItemStack(Material.WOOL, i));
cover.put(i, new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1));
tip.put(i, new ItemStack(Material.CLAY, i));
number.put(i, new ItemStack(Material.WHITE_WOOL, i));
continue;
}

tipItem = ItemStackUtility.getItemStack(items.getString(i + "." + "tip" + ".materialData", "HARD_CLAY"));
coverItem = ItemStackUtility.getItemStack(items.getString(i + "." + "cover" + ".materialData", "STAINED_GLASS_PANE"));
numberItem = ItemStackUtility.getItemStack(items.getString(i + "." + "number" + ".materialData", "WOOL"));
tipItem = ItemStackUtility.getItemStack(items.getString(i + "." + "tip" + ".materialData", "CLAY"));
coverItem = ItemStackUtility.getItemStack(items.getString(i + "." + "cover" + ".materialData", "LIGHT_GRAY_STAINED_GLASS_PANE"));
numberItem = ItemStackUtility.getItemStack(items.getString(i + "." + "number" + ".materialData", "WHITE_WOOL"));
if(tipItem == null){
tipItem = new ItemStack(Material.HARD_CLAY, 1);
tipItem = new ItemStack(Material.CLAY, 1);
game.warn(ChatColor.RED.toString() + i + "." + "tip" + ".materialData" + " not valid material");
}
if(coverItem == null){
coverItem = new ItemStack(Material.STAINED_GLASS_PANE, 1);
coverItem = new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE, 1);
game.warn(ChatColor.RED.toString() + i + "." + "cover" + ".materialData" + " not valid material");
}
if(numberItem == null){
numberItem = new ItemStack(Material.WOOL, 1);
numberItem = new ItemStack(Material.WHITE_WOOL, 1);
game.warn(ChatColor.RED.toString() + i + "." + "number" + ".materialData" + " not valid material");
}
ItemMeta meta = tipItem.getItemMeta();
Expand Down Expand Up @@ -189,10 +189,9 @@ public void removeFromGame(UUID uuid) {
public void loadGameRules(ConfigurationSection buttonSec, String buttonID) {
double cost = buttonSec.getDouble("cost", 0.);
boolean saveStats = buttonSec.getBoolean("saveStats", false);
boolean restartButton = buttonSec.getBoolean("restartButton", true);
int token = buttonSec.getInt("token", 0);
int money = buttonSec.getInt("money", 0);
gameTypes.put(buttonID, new SudokuGameRules(buttonID, cost, money, token, restartButton, saveStats));
gameTypes.put(buttonID, new SudokuGameRules(buttonID, cost, money, token, saveStats));
}

@Override
Expand All @@ -218,6 +217,5 @@ public void onGameEnd(Player winner, String key) {
} else {
winner.sendMessage((lang.PREFIX + lang.GAME_WON));
}
game.onGameWon(winner, rule, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
* Game rules container for Sudoku
*/
public class SudokuGameRules extends GameRuleRewards {
private boolean restartButton;

public SudokuGameRules(String key, double cost, int reward, int tokens, boolean restartButton, boolean saveStats){
public SudokuGameRules(String key, double cost, int reward, int tokens, boolean saveStats){
super(key, saveStats, SaveType.WINS, cost, reward, tokens);
this.restartButton = restartButton;
}

public boolean hasRestartButton() {
return restartButton;
}
}
17 changes: 8 additions & 9 deletions src/main/java/me/nikl/logicpuzzles/threeinarow/ThreeInARow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import me.nikl.gamebox.GameBox;
import me.nikl.gamebox.game.Game;
import me.nikl.gamebox.game.GameSettings;
import me.nikl.logicpuzzles.LogicPuzzles;
import me.nikl.gamebox.utility.ItemStackUtility;
import me.nikl.gamebox.utility.StringUtility;
import me.nikl.logicpuzzles.LogicPuzzles;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

Expand Down Expand Up @@ -36,13 +36,13 @@ public void init() {
}

private void loadItems() {
blueTile = loadItem("game.blueTile", "wool:11");
whiteTile = loadItem("game.whiteTile", "wool");
blueTileTip = loadItem("game.blueTileTip", "stained_clay:11");
whiteTileTip = loadItem("game.whiteTileTip", "stained_clay");
wrongHelpItem = loadItem("game.wrongHelpItem", "stained_glass_pane:14");
correctHelpItem = loadItem("game.correctHelpItem", "stained_glass_pane:13");
backGround = loadItem("game.backGround", "stained_glass_pane:7");
blueTile = loadItem("game.blueTile", "BLUE_WOOL");
whiteTile = loadItem("game.whiteTile", "WHITE_WOOL");
blueTileTip = loadItem("game.blueTileTip", "BLUE_CONCRETE");
whiteTileTip = loadItem("game.whiteTileTip", "WHITE_CONCRETE");
wrongHelpItem = loadItem("game.wrongHelpItem", "ORANGE_STAINED_GLASS_PANE");
correctHelpItem = loadItem("game.correctHelpItem", "GREEN_STAINED_GLASS_PANE");
backGround = loadItem("game.backGround", "GRAY_STAINED_GLASS_PANE");
}

private ItemStack loadItem(String path, String defaultMaterial) {
Expand All @@ -67,7 +67,6 @@ public void loadSettings() {
gameSettings.setGameType(GameSettings.GameType.SINGLE_PLAYER);
gameSettings.setHandleClicksOnHotbar(false);
gameSettings.setGameGuiSize(54);
gameSettings.setGameBoxMinimumVersion("2.1.4");
}

@Override
Expand Down
Loading

0 comments on commit 2e35558

Please sign in to comment.