Added the ability to clone kits.

This commit is contained in:
Brianna 2021-03-08 09:54:49 -06:00
parent a899ccf426
commit 9ac672ff9b
5 changed files with 57 additions and 22 deletions

View File

@ -28,14 +28,14 @@ public class CommandCreatekit extends AbstractCommand {
if (args.length != 1) {
return ReturnType.SYNTAX_ERROR;
}
String kitStr = args[0].toLowerCase();
String kitStr = args[0].toLowerCase().trim();
if (plugin.getKitManager().getKit(kitStr) != null) {
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
plugin.getLocale().newMessage("&aThat kit doesn't exist. Creating it now.").sendPrefixedMessage(player);
Kit kit = new Kit(kitStr.trim());
Kit kit = new Kit(kitStr);
plugin.getKitManager().addKit(kit);
guiManager.showGUI(player, new KitEditorGui(plugin, player, kit, null));
return ReturnType.SUCCESS;

View File

@ -1,5 +1,6 @@
package com.songoda.ultimatekits.gui;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.gui.AnvilGui;
@ -305,6 +306,30 @@ public class KitEditorGui extends DoubleGui {
guiManager.showGUI(event.player, gui);
});
setPlayerButton(7, GuiUtils.createButtonItem(CompatibleMaterial.SHEEP_SPAWN_EGG,
plugin.getLocale().getMessage("interface.kiteditor.clone").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.clonelore")
.getMessage().split("\\|")),
(event) -> {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a new kit name");
gui.setAction(evnt -> {
String kitStr = gui.getInputText().toLowerCase().trim();
if (plugin.getKitManager().getKit(kitStr) != null) {
plugin.getLocale().getMessage("command.kit.kitalreadyexists").sendPrefixedMessage(player);
player.closeInventory();
} else {
Kit newKit = kit.clone(kitStr);
plugin.getKitManager().addKit(newKit);
player.closeInventory();
Bukkit.getScheduler().runTaskLater(plugin, () ->
guiManager.showGUI(player, new KitEditorGui(plugin, player, newKit, null)), 2L);
}
});
guiManager.showGUI(player, gui);
});
setPlayerButton(8, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.animationlore")
@ -319,22 +344,6 @@ public class KitEditorGui extends DoubleGui {
setInvItems();
});
setPlayerButton(8, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
plugin.getLocale().getMessage("interface.kiteditor.animation").getMessage(),
plugin.getLocale().getMessage("interface.kiteditor.animationlore")
.getMessage().split("\\|")),
(event) -> {
AnvilGui gui = new AnvilGui(player, this);
gui.setTitle("Enter a name for the new kit");
gui.setAction(evnt -> {
Kit newKit = kit.clone(gui.getInputText());
plugin.getKitManager().addKit(newKit);
player.closeInventory();
guiManager.showGUI(player, new KitEditorGui(plugin, player, newKit, null));
paint();
});
guiManager.showGUI(player, gui);
});
}

View File

@ -39,10 +39,10 @@ import java.util.Objects;
/**
* Created by songoda on 2/24/2017.
*/
public class Kit {
public class Kit implements Cloneable {
private final String key;
private final String name;
private String key;
private String name;
private Category category = null;
private static UltimateKits plugin;
@ -478,6 +478,26 @@ public class Kit {
return this;
}
public Kit clone(String key) {
try {
Kit newKit = (Kit) super.clone();
List<KitItem> contents = new ArrayList<>();
for (KitItem item : newKit.contents)
contents.add(item.clone());
newKit.setContents(contents);
newKit.key = key;
newKit.name = TextUtils.formatText(key, true);
return newKit;
} catch (CloneNotSupportedException e) {
return null;
}
}
@Override
public int hashCode() {
return 31 * (key != null ? key.hashCode() : 0);

View File

@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class KitItem {
public class KitItem implements Cloneable {
private KitContent content;
private KitItemType type;
@ -222,6 +222,10 @@ public class KitItem {
return type;
}
public KitItem clone() throws CloneNotSupportedException {
return (KitItem)super.clone();
}
@Override
public String toString() {
return "KitItem:{"

View File

@ -153,6 +153,8 @@ interface:
addeconomyok: '&8Money &5$%amount%&8 has been added to your kit.'
animation: '&6Kit Animation'
animationlore: '&7Currently: &6%animation%'
clone: '&aClone Kit'
clonelore: '&7Use this to create an identical|&7kit with a different name.'
itemediting: '&6Switch To Item Editing'
itemeditinglore: '&7Click to enable|&7item editing.'
itemmoving: '&6Switch To Item Moving'