Lets not overwrite tickets.

This commit is contained in:
Brianna 2020-09-08 16:30:59 -05:00
parent 427f428d1d
commit 4c44f73593
5 changed files with 18 additions and 16 deletions

View File

@ -61,7 +61,7 @@ public class CommandRunTemplate extends AbstractCommand {
return players;
} else if (args.length == 2) {
List<String> lines = new ArrayList<>();
for (Template template : plugin.getTemplateManager().getTemplates().values()) {
for (Template template : plugin.getTemplateManager().getTemplates()) {
lines.add(template.getName());
}
}

View File

@ -292,7 +292,8 @@ public class PunishGui extends Gui {
private void updateTemplate() {
Template template = new Template(this.type, this.duration, this.reason, this.template.getCreator(), this.templateName);
plugin.getTemplateManager().updateTemplate(this.template.getId(), template);
plugin.getTemplateManager().removeTemplate(this.template);
plugin.getTemplateManager().addTemplate(template);
plugin.getDataManager().deleteTemplate(this.template);
plugin.getDataManager().createTemplate(template);
justSaved = true;

View File

@ -41,7 +41,7 @@ public class TemplateManagerGui extends Gui {
int numTemplates = plugin.getTemplateManager().getTemplates().size();
this.pages = (int) Math.floor(numTemplates / 28.0);
List<Template> templates = plugin.getTemplateManager().getTemplates().values().stream().skip((page - 1) * 28).limit(28)
List<Template> templates = plugin.getTemplateManager().getTemplates().stream().skip((page - 1) * 28).limit(28)
.collect(Collectors.toList());
setNextPage(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
@ -91,8 +91,10 @@ public class TemplateManagerGui extends Gui {
if (player.hasPermission("um.templates.edit"))
guiManager.showGUI(player, new PunishGui(plugin, null, template, player));
} else if (event.clickType == ClickType.RIGHT) {
if (player.hasPermission("um.templates.destroy"))
if (player.hasPermission("um.templates.destroy")) {
plugin.getTemplateManager().removeTemplate(template);
plugin.getDataManager().deleteTemplate(template);
}
showPage();
}
});

View File

@ -33,7 +33,7 @@ public class TemplateSelectorGui extends Gui {
punish.runTask();
});
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values());
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates());
for (int i = 0; i < templates.size(); i++) {
Template template = templates.get(i);
setButton(18 + i, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText("&6&l" + template.getName()),

View File

@ -2,14 +2,16 @@ package com.songoda.ultimatemoderation.punish.template;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class TemplateManager {
private static final Map<Integer, Template> templates = new HashMap<>();
private static final List<Template> templates = new LinkedList<>();
public Template getTemplate(String name) {
for (Template template : templates.values()) {
for (Template template : templates) {
if (formatName(template.getName()).equals(formatName(name)))
return template;
}
@ -17,20 +19,17 @@ public class TemplateManager {
}
public Template addTemplate(Template template) {
return templates.put(template.getId(), template);
templates.add(template);
return template;
}
public Template removeTemplate(Template template) {
return templates.remove(template.getId());
templates.remove(template);
return template;
}
public Template updateTemplate(int id, Template template) {
templates.remove(id);
return addTemplate(template);
}
public Map<Integer, Template> getTemplates() {
return Collections.unmodifiableMap(templates);
public List<Template> getTemplates() {
return Collections.unmodifiableList(templates);
}
private String formatName(String name) {