Skip to content

Commit

Permalink
Mines recode (#47)
Browse files Browse the repository at this point in the history
* Deprecate old-style mine code

* Revert "Deprecate old-style mine code"

This reverts commit 8a0cd9b.

* Instead of legacy classes, legacy modules (#47)

* WIP

yeah i know it doesn't build but i have a life unfortunately

* More WIP

* Make do and mend

Not a good tactic but watever

* Fair progress on mine recode

* BlockBreakEvent supports XP, and much more

* A lot of progress

* Restore old constructor for historical reasons

Breaking change

* Done, just needs testing

* Reformat & optimize

* Finalize

* Complete

BUG: Mines reset will not recognize a reset until the server is reloaded

* Fix bug

* Maybe this will help?

* Revert "Fix bug"

This reverts commit 1dfe778.

* It didn't fix the bug :(

This reverts commit 1ea22c8.

* Now the bug is fixed
  • Loading branch information
Perksey committed Feb 26, 2018
1 parent 6a9b14c commit cd70b60
Show file tree
Hide file tree
Showing 42 changed files with 10,771 additions and 36 deletions.
8,501 changes: 8,501 additions & 0 deletions prison-core/out/production/resources/items.csv

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions prison-core/out/production/resources/lang/core/de_DE.properties
@@ -0,0 +1,37 @@
#
# Prison ist ein Minecraft Plug-In für das Prison Spielmodus.
# Copyright (C) 2017 The Prison Team
#
# Dieses Programm ist kostenlose Software: Sie können es
# weiterverbreiten und/oder es modifizieren unter den
# Bedingungen der GNU General Public Lizenz wie veröffentlicht
# von der Free Software Foundation, entweder Version 3 der
# Lizenz, oder (nach Ihrem Wunsch) jegliche neuere Version.
#
# Dieses Programm wird distribuiert in der Hoffnung, dass es
# hilfreich ist, allerdings OHNE JEGLICHE GARANTIEN; auch ohne
# die implizierte Garantie der MERCHANT ABILITY oder FITNESS
# FOR A PARTICULAR PURPOSE. Siehe GNU General Public Lizenz
# für nähere Informationen.
#
# Sie sollten eine Kopie der GNU General Public Lizenz erhalten
# haben zusammen mit diesem Programm. Sollte dies nicht der
# Fall sein, siehe http://gnu.org/licences/.
#
includeError=[%1] hat einen ungültigen Wert.
excludeError=[%1] hat einen ungültigen Wert.
cantAsConsole=Sie können dies nicht als Konsole machen.
missingArgument=Das Argument [%1] ist nicht definiert (es hat keinen Standardwert).
missingFlagArgument=Das Kennzeichen -%1 besitzt nicht die nötigen Parameter.
undefinedFlagArgument=Das Argument [%1] zu dem Kennzeichen -%2 ist nicht definiert.
internalErrorOccured=Ein interner Error trat auf bei dem Versuch, diesen Befehl auszuführen.
noPermission=Sie haben nicht die benötigten Erlaubnisse, um diesen Befehl auszuführen.
blockParseError=Der Parameter [%1] ist kein gültiger Block.
numbetParseError=Der Parameter [%1] ist keine Nummer.
numberTooLow=Der Parameter [%1] muss gleich oder größer sein als %2.
numberTooHigh=Der Parameter [%1] muss gleich oder kleiner sein als %2.
numberRangeError=Der Parameter [%1] muss gleich oder größer sein als %2 und kleiner als oder gleich %3.
tooFewCharacters=Der Parameter [%1] muss gleich oder größer als %2 Zeichen sein.
tooManyCharacters=Der Parameter [%1] muss gleich oder kleiner als %2 Zeichen sein.
playerNotOnline=Der Spieler %1 ist nicht online.
worldNotFound=Die Welt %1 wurde nicht gefunden.
34 changes: 34 additions & 0 deletions prison-core/out/production/resources/lang/core/en_GB.properties
@@ -0,0 +1,34 @@
#
# Prison is a Minecraft plugin for the prison game mode.
# Copyright (C) 2017 The Prison Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
includeError=[%1] has an invalid value.
excludeError=[%1] has an invalid value.
cantAsConsole=You can't do this as console.
missingArgument=The argument [%1] is not defined (it has no default value).
missingFlagArgument=The flag -%1 does not have the required parameters.
undefinedFlagArgument=The argument [%1] to the flag -%2 is not defined.
internalErrorOccurred=An internal error occurred while attempting to perform this command.
noPermission=You lack the necessary permissions to perform this command.
blockParseError=The parameter [%1] is not a valid block.
numberParseError=The parameter [%1] is not a number.
numberTooLow=The parameter [%1] must be equal or greater than %2.
numberTooHigh=The parameter [%1] must be equal or less than %2.
numberRangeError=The parameter [%1] must be equal or greater than %2 and less than or equal to %3.
tooFewCharacters=The parameter [%1] must be equal or greater than %2 characters.
tooManyCharacters=The parameter [%1] must be equal or less than %2 characters.
playerNotOnline=The player %1 is not online.
worldNotFound=The world %1 was not found.
34 changes: 34 additions & 0 deletions prison-core/out/production/resources/lang/core/en_US.properties
@@ -0,0 +1,34 @@
#
# Prison is a Minecraft plugin for the prison game mode.
# Copyright (C) 2017 The Prison Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
includeError=[%1] has an invalid value.
excludeError=[%1] has an invalid value.
cantAsConsole=You can't do this as console.
missingArgument=The argument [%1] is not defined (it has no default value).
missingFlagArgument=The flag -%1 does not have the required parameters.
undefinedFlagArgument=The argument [%1] to the flag -%2 is not defined.
internalErrorOccurred=An internal error occurred while attempting to perform this command.
noPermission=You lack the necessary permissions to perform this command.
blockParseError=The parameter [%1] is not a valid block.
numberParseError=The parameter [%1] is not a number.
numberTooLow=The parameter [%1] must be equal or greater than %2.
numberTooHigh=The parameter [%1] must be equal or less than %2.
numberRangeError=The parameter [%1] must be equal or greater than %2 and less than or equal to %3.
tooFewCharacters=The parameter [%1] must be equal or greater than %2 characters.
tooManyCharacters=The parameter [%1] must be equal or less than %2 characters.
playerNotOnline=The player %1 is not online.
worldNotFound=The world %1 was not found.
34 changes: 34 additions & 0 deletions prison-core/out/production/resources/lang/core/hu_HU.properties
@@ -0,0 +1,34 @@
#
# A Prison Minecraft plugin a börtön játékmódhoz.
# Copyright (C) 2017 The Prison Team
#
# Ez a program szabad szoftver: eloszthatja és/vagy módosíthatja
# a GNU Általános Nyilvános Licenc feltételei szerint
# a Szabad Szoftver Alapítvány, vagy a Licenc 3. verziója, vagy
# (tetszés szerint) minden későbbi verzióban.
#
# Ezt a programot abban a reményben osztják szét, hogy hasznos lesz,
# de MINDEN GARANCIA NÉLKÜL; anélkül, hogy az implikált garanciát
# A KERESKEDELEMBIZTONSÁG VAGY EGY ADOTT CÉLRA VALÓ ALKALMASSÁG. Lásd a
# További részleteket a GNU General Public License.
#
# Meg kellett volna kapnia egy példányt a GNU General Public License-ből
# ezzel a programmal együtt. Ha nem, nézze meg <http://www.gnu.org/licenses/>.
#
includeError=[%1] érvénytelen értékkel rendelkezik.
excludeError=[%1] érvénytelen értékkel rendelkezik.
cantAsConsole=Ezt nem teheted konzolként.
missingArgument=A(z) [%1] argumentum nincs megadva (nincs alapértelmezett értéke).
missingFlagArgument=A zászló -%1 nem rendelkezik a szükséges paraméterekkel.
undefinedFlagArgument=A(z) [%1] argumentum a zászlóra -%2 nincs definiálva.
internalErrorOccurred=Belső hiba történt a parancs végrehajtása közben.
noPermission=A parancs végrehajtásához nincsenek szükséges engedélyek.
blockParseError=A(z) [%1] paraméter nem érvényes blokk.
numberParseError=A(z) [%1] paraméter nem szám.
numberTooLow=A(z) [%1] paraméternek egyenlőnek vagy nagyobbnak kell lennie, mint %2.
numberTooHigh=A(z) [%1] paraméternek egyenlőnek vagy kisebbnek kell lennie, mint %2.
numberRangeError=A(z) [%1] paraméternek azonosnak vagy nagyobbnak kell lennie, mint %2, és kisebb vagy egyenlő, mint %3.
tooFewCharacters=A(z) [%1] paraméternek egyenlőnek vagy nagyobbnak kell lennie, mint %2 karakter.
tooManyCharacters=A(z) [%1] paraméternek egyenlőnek vagy kisebbnek kell lennie, mint %2 karakter.
playerNotOnline=A(z) %1 játékos nem online.
worldNotFound=A(z) %1 világ nem található.
29 changes: 29 additions & 0 deletions prison-core/out/production/resources/lang/mines/en_US.properties
@@ -0,0 +1,29 @@
reset_warning=&7All mines are going to reset in &3%1&7.
reset_message=&7All mines have been reset.
not_allowed=&7You are not allowed to mine here.
autosmelt_enable=&bAutosmelt &7has been &aenabled&7.
autosmelt_disable=&bAutosmelt &7has been &cdisabled&7.
autoblock_enable=&bAutoblock &7has been &aenabled&7.
autoblock_disable=&bAutoblock &7has been &cdisabled&7.
autopickup_enable=&bAutopickup &7has been &aenabled&7.
autopickup_disable=&bAutopickup &7has been &cdisabled&7.
teleported=&7Teleported to mine &3%1&7.
mine_reset=&7The mine has been reset.
mine_reset_fail=&7Could not reset the mine. &8Check the console for details.
mine_created=&7Successfully created the mine.
mine_deleted=&7Successfully deleted the mine.
select_bounds=&7You need to select the mine boundaries first. &8Type /mines wand to do so.
world_diff=&7You may not create mines across two different worlds.
mine_exists=&7A mine by that name already exists.
mine_does_not_exist=&7A mine by that name does not exist.
spawn_set=&7The mine spawnpoint has been set.
spawnpoint_same_world=&7The &cspawnpoint &7must be in the same &cworld &7as the mine.
not_a_block=&c%1 &7is not a block.
block_already_added=&7That block has already been added to the mine.
mine_full=&cThe mine will be too full. &7Try lowering the percentage of this block and/or other blocks in the mine to make some room.
block_added=&7Added block &3%1 &7to mine &3%2&7.
block_set=&7Changed block &3%1 &7in mine &3%2&7.
block_not_removed=&7That block is not in this mine.
block_deleted=&7Removed block &3%1 &7from mine &3%2&7.
mine_redefined=&7Successfully &3redefined &7the mine.
missing_world=&7The world that the mine was created in can't be found.
27 changes: 27 additions & 0 deletions prison-core/out/production/resources/lang/mines/hu_HU.properties
@@ -0,0 +1,27 @@
reset_warning=&7Minden bánya újratöltve &3%1&7.
reset_message=&7Az összes bánya vissza lett állítva.
not_allowed=&7A bányászás nem megengedett.
autosmelt_enable=&bAz auto. égetés &7engedélyezve.
autosmelt_disable=&bAz auto. égetés &7letiltva.
autoblock_enable=&bAz auto. blokk &7engedélyezve.
autoblock_disable=&bAz auto. blokk &7letiltva.
teleported=&7Teleportálás a(z) &3%1&7 bányához.
mine_reset=&7A bánya újratöltve.
mine_reset_fail=&7Nem lehet újratölteni a bányát. &8A részletekért nézze meg a konzolt.
mine_created=&7A bánya sikeresen létrehozva.
mine_deleted=&7A bánya sikeresen törölve.
select_bounds=&7Először ki kell választani a bánya határait. &8Típus /mines wand.
world_diff=&7Nem hozhatsz létre bányákat két különböző világon.
mine_exists=&7A bánya ezzel a névvel már létezik.
mine_does_not_exist=&7A bánya ezzel a névvel nem létezik.
spawn_set=&7A bánya spawnpontja beállítva.
spawnpoint_same_world=&7A &cspawnpont-nak&7 ugyanabban a &cvilágban&7 bányában kell lennie.
not_a_block=&c%1 &7nem egy blokk.
block_already_added=&7Ez a blokk már felkerült a bányába.
mine_full=&cA bánya túlságosan tele lesz. &7Jobban próbáld csökkenteni a blokk és/vagy más blokkok százalékos arányát a bányában.
block_added=&7A blokk hozzáadva &3%1 &7a(z) &3%2&7 bányához.
block_set=&7A blokk változtatva &3%1 &7a(z) &3%2&7 bányában.
block_not_removed=&7Ez a blokk nem ebben a bányában van.
block_deleted=&7A blokk törölve &3%1 &7a(z) &3%2&7 bányából.
mine_redefined=&7A bányát sikeresen &3újradefiniálta&7.
missing_world=&7Nem található meg a világ, amelyet a bányát hoztak létre.
Expand Up @@ -35,11 +35,17 @@ public class BlockBreakEvent implements Cancelable {
private Location blockLocation;
private Player player;
private boolean canceled = false;
private int exp;

public BlockBreakEvent(BlockType block, Location blockLocation, Player player) {
this(block,blockLocation,player,0);
}

public BlockBreakEvent(BlockType block, Location blockLocation, Player player,int xp) {
this.block = block;
this.blockLocation = blockLocation;
this.player = player;
this.exp = xp;
}

@Override public boolean isCanceled() {
Expand All @@ -62,4 +68,6 @@ public Player getPlayer() {
return player;
}

public int getExpToDrop() {return exp;}

}
Expand Up @@ -133,6 +133,7 @@ public interface PlayerInventory extends Inventory {
*/
ItemStack getItemInLeftHand();


/**
* Sets the item in the players left (off) hand
*
Expand Down
10 changes: 6 additions & 4 deletions prison-core/src/main/resources/lang/mines/en_US.properties
@@ -1,10 +1,12 @@
reset_warning=&7All mines are going to reset in &3%1&7.
reset_message=&7All mines have been reset.
not_allowed=&7You are not allowed to mine here.
autosmelt_enable=&bAutosmelt &7has been enabled.
autosmelt_disable=&bAutosmelt &7has been disabled.
autoblock_enable=&bAutoblock &7has been enabled.
autoblock_disable=&bAutoblock &7has been disabled.
autosmelt_enable=&bAutosmelt &7has been &aenabled&7.
autosmelt_disable=&bAutosmelt &7has been &cdisabled&7.
autoblock_enable=&bAutoblock &7has been &aenabled&7.
autoblock_disable=&bAutoblock &7has been &cdisabled&7.
autopickup_enable=&bAutopickup &7has been &aenabled&7.
autopickup_disable=&bAutopickup &7has been &cdisabled&7.
teleported=&7Teleported to mine &3%1&7.
mine_reset=&7The mine has been reset.
mine_reset_fail=&7Could not reset the mine. &8Check the console for details.
Expand Down
14 changes: 14 additions & 0 deletions prison-mines-legacy/build.gradle
@@ -0,0 +1,14 @@
group 'tech.mcprison'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile project(':prison-core')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
@@ -0,0 +1,120 @@
package tech.mcprison.prison.mines;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import tech.mcprison.prison.Prison;
import tech.mcprison.prison.PrisonAPI;
import tech.mcprison.prison.convert.ConversionAgent;
import tech.mcprison.prison.convert.ConversionResult;
import tech.mcprison.prison.error.Error;
import tech.mcprison.prison.output.Output;
import tech.mcprison.prison.util.BlockType;
import tech.mcprison.prison.util.Bounds;
import tech.mcprison.prison.util.Location;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* @author Faizaan A. Datoo
*/
public class MinesConversionAgent implements ConversionAgent {

@Override public ConversionResult convert() {
File oldFolder = new File(PrisonAPI.getPluginDirectory().getParent(), "Prison.old");
File minesFolder = new File(oldFolder, "mines");

File alreadyConverted = new File(minesFolder, ".converted");
if (alreadyConverted.exists()) {
return ConversionResult.failure(getName(),
"Already converted. Delete the '/plugins/Prison.old/mines' folder.");
}

String[] jsonFiles = minesFolder.list((dir, name) -> name.endsWith(".json"));

try {

// -----------
// JSON
// -----------

if (jsonFiles != null) {
for (String jsonFile : jsonFiles) {
File jsonFileObj = new File(minesFolder, jsonFile);
JsonParser parser = new JsonParser();
String json = new String(Files.readAllBytes(jsonFileObj.toPath()));
JsonObject obj = (JsonObject) parser.parse(json);

String name = obj.getAsJsonPrimitive("name").getAsString();
String world = obj.getAsJsonPrimitive("world").getAsString();
double minX = obj.getAsJsonPrimitive("minX").getAsInt();
double minY = obj.getAsJsonPrimitive("minY").getAsInt();
double minZ = obj.getAsJsonPrimitive("minZ").getAsInt();
double maxX = obj.getAsJsonPrimitive("maxX").getAsInt();
double maxY = obj.getAsJsonPrimitive("maxY").getAsInt();
double maxZ = obj.getAsJsonPrimitive("maxZ").getAsInt();

Optional<tech.mcprison.prison.internal.World> prisonWorld =
Prison.get().getPlatform().getWorld(world);
if (!prisonWorld.isPresent()) {
Output.get().logWarn(String.format(
"Can't convert mine %s because its world %s doesn't exist anymore.",
name, world));
break; // Skip it, its world didn't exist.
}

Bounds bounds = new Bounds(new Location(prisonWorld.get(), minX, minY, minZ),
new Location(prisonWorld.get(), maxX, maxY, maxZ));

HashMap<BlockType, Integer> blocks = new HashMap<>();
for (Map.Entry<String, JsonElement> blockEntry : obj.getAsJsonObject("blocks")
.entrySet()) {
String[] blockParts = blockEntry.getKey().split(":");
BlockType type = BlockType.getBlock(Integer.parseInt(blockParts[0]),
Short.parseShort(blockParts[1]));

// Prison 2 stores chances in values < 1, whereas Prison 3 does it < 100
int chance = (int) ((blockEntry.getValue().getAsDouble()) * 100);

blocks.put(type, chance);
}

Mine ourMine = new Mine();
ourMine.setName(name);
ourMine.setBounds(bounds);
ourMine.setBlocks(blocks);

if (PrisonMines.get().getMines().contains(ourMine)) {
break;
}

PrisonMines.get().getMines().add(ourMine);
}

PrisonMines.get().getMines().save();
alreadyConverted.createNewFile();
return new ConversionResult(getName(), ConversionResult.Status.Success,
"Converted " + jsonFiles.length + " mines.");
} else {
alreadyConverted.createNewFile();
return new ConversionResult(getName(), ConversionResult.Status.Success,
"Converted 0 mines.");
}
} catch (IOException e) {
PrisonMines.get().getErrorManager().throwError(
new Error("Encountered an error while converting mines.")
.appendStackTrace("while loading mines", e));
return new ConversionResult(getName(), ConversionResult.Status.Failure,
"IOException, check console for details");
}
}

@Override public String getName() {
return "Mines";
}
}

0 comments on commit cd70b60

Please sign in to comment.