Skip to content

Commit

Permalink
Remove performCommand usage, as it does not work.
Browse files Browse the repository at this point in the history
Spigot does not return value that is set in command. It just returns if command is handled or not.
  • Loading branch information
BONNe committed Jan 6, 2019
1 parent 75dd35a commit c5091c3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;

import java.util.Collections;
Expand Down Expand Up @@ -64,8 +65,6 @@ public AdminBiomeEditPanel(BiomesAddon addon,
{
this.biome = biome;
}

this.commandHeader = topLabel + " " + BIOMES + " " + EDIT + " ";
}


Expand Down Expand Up @@ -113,34 +112,65 @@ public void build()
(panel, user1, clickType, slot) -> {
if (this.disableButtons)
{
BiomesObject biomesObject =
new BiomesObject(Utils.getBiomeNameMap().get(this.valueObject), this.world);
biomesObject.setFriendlyName("New Biome");
// Create tempBiome and try to save it.
BiomesObject tempBiome =
new BiomesObject((Biome) this.valueObject, this.world);
tempBiome.setFriendlyName("New Biome");

if (this.addon.getAddonManager().storeBiome(biomesObject, false, this.user, true))
if (this.addon.getAddonManager().storeBiome(tempBiome, false, this.user, true))
{
this.user.sendMessage("biomes.messages.information.saved", "[biome]", biomesObject.getFriendlyName());
// If save was successful then send information about it to user, and set tempBiome as current biome.
this.user.sendMessage("biomes.messages.information.saved", "[biome]", tempBiome.getFriendlyName());
this.currentEditMode = PropertyButtons.NULL;
this.biome = biomesObject;
this.valueObject = null;
this.biome = tempBiome;
}
else
{
// If biome saving was not successful, then throw error.
this.user.sendMessage("biomes.messages.errors.exist-biome");
this.valueObject = null;
}
}
else
{
if (this.user.performCommand(
this.commandHeader + this.biome.getBiomeName() + " biomeName " +
this.valueObject))
if (!(this.valueObject instanceof Biome))
{
this.user.sendMessage("biomes.messages.errors.incorrect-biome");
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
else if (this.biome.getBiomeID() == ((Biome) this.valueObject).ordinal())
{
this.user.sendMessage("biomes.messages.warning.same-biome");
this.currentEditMode = PropertyButtons.NULL;
}
else
{
// Create tempBiome to check if exist biome with the same ID.
BiomesObject tempBiome = new BiomesObject((Biome) this.valueObject, this.world);

if (this.addon.getAddonManager().getBiomeFromString(tempBiome.getUniqueId()) != null)
{
// Throw error if biome is find.
this.user.sendMessage("biomes.messages.errors.exist-biome");
}
else
{
// Remove biome from memory as it is necessary to change its unique id.
this.addon.getAddonManager().removeBiome(this.biome);

// Update biomeName, biome ID, uniqueID
this.biome.setBiomeName(tempBiome.getBiomeName());
this.biome.setBiomeID(tempBiome.getBiomeID());
this.biome.setUniqueId(tempBiome.getUniqueId());

this.addon.getAddonManager().saveBiome(this.biome);

this.currentEditMode = PropertyButtons.NULL;
}
}
}

this.valueObject = null;

this.build();
return true;
}));
Expand All @@ -164,11 +194,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(1, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " friendlyName " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setFriendlyName((String) this.valueObject);
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand All @@ -192,11 +221,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(10, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " deployed " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setDeployed((boolean) this.valueObject);
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand All @@ -221,11 +249,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(3, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " description " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setDescription(Utils.splitString((String) this.valueObject));
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand All @@ -249,11 +276,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(19, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " icon " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setIcon((ItemStack) this.valueObject);
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand All @@ -278,11 +304,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(19, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " requiredLevel " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setRequiredLevel((int) this.valueObject);
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand Down Expand Up @@ -324,11 +349,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(37, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " requiredCost " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setRequiredCost((int) this.valueObject);
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand Down Expand Up @@ -370,11 +394,10 @@ public void build()
// Create save button with custom handler
panelBuilder.item(46, this.createCommonButton(CommonButtons.SAVE,
(panel, user1, clickType, slot) -> {
if (this.user.performCommand(this.commandHeader + this.biome.getBiomeName() + " permission " + this.valueObject))
{
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;
}
this.biome.setPermission((String) this.valueObject);
this.addon.getAddonManager().saveBiome(this.biome);
this.currentEditMode = PropertyButtons.NULL;
this.valueObject = null;

this.build();
return true;
Expand Down Expand Up @@ -701,6 +724,4 @@ private enum PropertyButtons
private PropertyButtons currentEditMode;

private PanelItem returnButton;

private final String commandHeader;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private PanelItem createBiomeButton(Biome biome)
name(biome.name()).
icon(Material.MAP).
clickHandler((panel, user, clickType, slot) -> {
this.targetPanel.setValueObject(biome.name());
this.targetPanel.setValueObject(biome);
this.targetPanel.build();
return true;
}).build();
Expand Down

0 comments on commit c5091c3

Please sign in to comment.