|
|
@ -1,8 +1,10 @@ |
|
|
|
package ru.simsonic.rscPermissions.Engine.Backends; |
|
|
|
package ru.simsonic.rscPermissions.Engine.Backends; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.LinkedList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import ru.simsonic.rscMinecraftLibrary.Bukkit.GenericChatCodes; |
|
|
|
import ru.simsonic.rscMinecraftLibrary.Bukkit.GenericChatCodes; |
|
|
|
import ru.simsonic.rscPermissions.API.RowEntity; |
|
|
|
import ru.simsonic.rscPermissions.API.RowEntity; |
|
|
@ -12,13 +14,13 @@ import ru.simsonic.rscPermissions.BukkitPluginMain; |
|
|
|
|
|
|
|
|
|
|
|
public class DatabaseEditor extends BackendDatabase |
|
|
|
public class DatabaseEditor extends BackendDatabase |
|
|
|
{ |
|
|
|
{ |
|
|
|
private final BukkitPluginMain plugin; |
|
|
|
// private final BukkitPluginMain plugin;
|
|
|
|
private final Map<String, RowEntity> entities = new HashMap<>(); |
|
|
|
private final Map<String, RowEntity> entities = new HashMap<>(); |
|
|
|
private final Map<String, RowPermission> permissions = new HashMap<>(); |
|
|
|
private final Map<String, RowPermission> permissions = new HashMap<>(); |
|
|
|
private final Map<String, RowInheritance> inheritance = new HashMap<>(); |
|
|
|
private final Map<String, RowInheritance> inheritance = new HashMap<>(); |
|
|
|
public DatabaseEditor(BukkitPluginMain rscp) |
|
|
|
public DatabaseEditor(BukkitPluginMain rscp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.plugin = rscp; |
|
|
|
// this.plugin = rscp;
|
|
|
|
} |
|
|
|
} |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public DatabaseContents retrieveContents() |
|
|
|
public DatabaseContents retrieveContents() |
|
|
@ -107,14 +109,31 @@ public class DatabaseEditor extends BackendDatabase |
|
|
|
for(RowPermission row : contents.permissions) |
|
|
|
for(RowPermission row : contents.permissions) |
|
|
|
if(row.id == remove.id) |
|
|
|
if(row.id == remove.id) |
|
|
|
sameIDs.add(row); |
|
|
|
sameIDs.add(row); |
|
|
|
if(sameIDs.isEmpty() == false) |
|
|
|
return rowFromPermissionClones(sameIDs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private RowInheritance restoreInheritanceAfterDelete(DatabaseContents contents, RowInheritance remove) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
final LinkedList<RowInheritance> sameIDs = new LinkedList<>(); |
|
|
|
|
|
|
|
for(RowInheritance row : contents.inheritance) |
|
|
|
|
|
|
|
if(row.id == remove.id) |
|
|
|
|
|
|
|
sameIDs.add(row); |
|
|
|
|
|
|
|
return rowFromInheritanceClones(sameIDs); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private RowPermission rowFromPermissionClones(List<RowPermission> clones) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(clones == null) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
if(clones.isEmpty()) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
final HashSet<String> names = new HashSet<>(); |
|
|
|
final HashSet<String> names = new HashSet<>(); |
|
|
|
final HashSet<String> perms = new HashSet<>(); |
|
|
|
final HashSet<String> perms = new HashSet<>(); |
|
|
|
final HashSet<String> dests = new HashSet<>(); |
|
|
|
final HashSet<String> dests = new HashSet<>(); |
|
|
|
for(RowPermission row : sameIDs) |
|
|
|
for(RowPermission row : clones) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// assert remove.value == row.value;
|
|
|
|
// assert remove.id == row.id;
|
|
|
|
|
|
|
|
// assert remove.value == row.value;
|
|
|
|
// assert remove.expirience == row.expirience;
|
|
|
|
// assert remove.expirience == row.expirience;
|
|
|
|
// assert remove.entityType.equals(row.entityType);
|
|
|
|
// assert remove.entityType.equals(row.entityType);
|
|
|
|
// assert remove.lifetime.equals(row.lifetime);
|
|
|
|
// assert remove.lifetime.equals(row.lifetime);
|
|
|
@ -122,33 +141,31 @@ public class DatabaseEditor extends BackendDatabase |
|
|
|
perms.add(row.permission); |
|
|
|
perms.add(row.permission); |
|
|
|
dests.add(row.destination.toString()); |
|
|
|
dests.add(row.destination.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
try |
|
|
|
final RowPermission merged = clones.get(0).clone(); |
|
|
|
{ |
|
|
|
merged.entity = GenericChatCodes.glue(names.toArray(new String[names.size()]), "; \n"); |
|
|
|
final RowPermission merged = remove.clone(); |
|
|
|
merged.permission = GenericChatCodes.glue(perms.toArray(new String[perms.size()]), "; \n"); |
|
|
|
merged.entity = GenericChatCodes.glue(names.toArray(new String[names.size()]), "; \n"); |
|
|
|
merged.destinationSource = GenericChatCodes.glue(dests.toArray(new String[dests.size()]), "; \n"); |
|
|
|
merged.permission = GenericChatCodes.glue(perms.toArray(new String[perms.size()]), "; \n"); |
|
|
|
return merged; |
|
|
|
merged.destinationSource = GenericChatCodes.glue(dests.toArray(new String[dests.size()]), "; \n"); |
|
|
|
} catch(CloneNotSupportedException ex) { |
|
|
|
return merged; |
|
|
|
// IMPOSSIBLE
|
|
|
|
} catch(CloneNotSupportedException ex) { |
|
|
|
|
|
|
|
// IMPOSSIBLE
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
private RowInheritance restoreInheritanceAfterDelete(DatabaseContents contents, RowInheritance remove) |
|
|
|
private RowInheritance rowFromInheritanceClones(List<RowInheritance> clones) |
|
|
|
{ |
|
|
|
{ |
|
|
|
final LinkedList<RowInheritance> sameIDs = new LinkedList<>(); |
|
|
|
if(clones == null) |
|
|
|
for(RowInheritance row : contents.inheritance) |
|
|
|
return null; |
|
|
|
if(row.id == remove.id) |
|
|
|
if(clones.isEmpty()) |
|
|
|
sameIDs.add(row); |
|
|
|
return null; |
|
|
|
if(sameIDs.isEmpty() == false) |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
final HashSet<String> names = new HashSet<>(); |
|
|
|
final HashSet<String> names = new HashSet<>(); |
|
|
|
final HashSet<String> prnts = new HashSet<>(); |
|
|
|
final HashSet<String> prnts = new HashSet<>(); |
|
|
|
final HashSet<String> dests = new HashSet<>(); |
|
|
|
final HashSet<String> dests = new HashSet<>(); |
|
|
|
for(RowInheritance row : sameIDs) |
|
|
|
for(RowInheritance row : clones) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// assert remove.value == row.value;
|
|
|
|
// assert remove.id == row.id;
|
|
|
|
|
|
|
|
// assert remove.value == row.value;
|
|
|
|
// assert remove.expirience == row.expirience;
|
|
|
|
// assert remove.expirience == row.expirience;
|
|
|
|
// assert remove.entityType.equals(row.entityType);
|
|
|
|
// assert remove.entityType.equals(row.entityType);
|
|
|
|
// assert remove.lifetime.equals(row.lifetime);
|
|
|
|
// assert remove.lifetime.equals(row.lifetime);
|
|
|
@ -156,16 +173,13 @@ public class DatabaseEditor extends BackendDatabase |
|
|
|
prnts.add(row.parent); |
|
|
|
prnts.add(row.parent); |
|
|
|
dests.add(row.destination.toString()); |
|
|
|
dests.add(row.destination.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
try |
|
|
|
final RowInheritance merged = clones.get(0).clone(); |
|
|
|
{ |
|
|
|
merged.entity = GenericChatCodes.glue(names.toArray(new String[names.size()]), "; \n"); |
|
|
|
final RowInheritance merged = remove.clone(); |
|
|
|
merged.parent = GenericChatCodes.glue(prnts.toArray(new String[prnts.size()]), "; \n"); |
|
|
|
merged.entity = GenericChatCodes.glue(names.toArray(new String[names.size()]), "; \n"); |
|
|
|
merged.destinationSource = GenericChatCodes.glue(dests.toArray(new String[dests.size()]), "; \n"); |
|
|
|
merged.parent = GenericChatCodes.glue(prnts.toArray(new String[prnts.size()]), "; \n"); |
|
|
|
return merged; |
|
|
|
merged.destinationSource = GenericChatCodes.glue(dests.toArray(new String[dests.size()]), "; \n"); |
|
|
|
} catch(CloneNotSupportedException ex) { |
|
|
|
return merged; |
|
|
|
// IMPOSSIBLE
|
|
|
|
} catch(CloneNotSupportedException ex) { |
|
|
|
|
|
|
|
// IMPOSSIBLE
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|