Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Move vote type registration. Remove custom votifier vote event and re…
Browse files Browse the repository at this point in the history
…gister exiting event. Modify several syntaxes. Increase plugin version.
  • Loading branch information
RezzedUp committed Jun 25, 2017
1 parent 0c04296 commit 16ac1c5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 93 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.rezzedup</groupId>
<artifactId>skript-votifier-hook</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import com.rezzedup.skriptvotifierhook.events.OnlinePlayerVoteEvent;
import com.rezzedup.skriptvotifierhook.events.VoteReceivedEvent;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VotifierEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.IOException;
Expand All @@ -24,53 +17,12 @@ public class SkriptVotifierHook extends JavaPlugin implements Listener
@Override
public void onEnable()
{
SkriptAddon addon = Skript.registerAddon(this);

Classes.registerClass
(
new ClassInfo<>(Vote.class, "vote")
.user("vote")
.name("Vote")
.description("A vote from votifier.")
.since("1.0.0")
.defaultExpression(new EventValueExpression<Vote>(Vote.class))
.parser(new Parser<Vote>()
{
@Override
public Vote parse(String s, ParseContext context)
{
return null;
}

@Override
public boolean canParse(ParseContext context)
{
return false;
}

@Override
public String toString(Vote vote, int i)
{
return vote.toString();
}

@Override
public String toVariableNameString(Vote vote)
{
return toString(vote, 0);
}

@Override
public String getVariableNamePattern()
{
return ".+";
}
})
);

try
{
addon.loadClasses("com.rezzedup.skriptvotifierhook", "events", "expressions");
Skript.registerAddon(this).loadClasses
(
"com.rezzedup.skriptvotifierhook", "types", "events", "expressions"
);
}
catch (IOException io)
{
Expand All @@ -83,16 +35,12 @@ public String getVariableNamePattern()
@EventHandler
public void on(VotifierEvent event)
{
PluginManager manager = getServer().getPluginManager();
Vote vote = event.getVote();

manager.callEvent(new VoteReceivedEvent(vote));

Player player = getServer().getPlayerExact(vote.getUsername());

if (player != null)
{
manager.callEvent(new OnlinePlayerVoteEvent(player, vote));
getServer().getPluginManager().callEvent(new OnlinePlayerVoteEvent(player, vote));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,23 @@
import ch.njol.skript.registrations.EventValues;
import com.rezzedup.skriptvotifierhook.GoGetter;
import com.vexsoftware.votifier.model.Vote;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.vexsoftware.votifier.model.VotifierEvent;

public class VoteReceivedEvent extends Event
public class VoteReceivedEvent
{
private static final HandlerList HANDLERS = new HandlerList();

public static final String[] PATTERNS = new String[]
{
"[raw] [votifier] vote receiv(e|ed)",
"[raw] votifier vote"
"[(any|every|raw)] [votifier] vote receiv(e|ed)",
"[(any|every|raw)] votifier vote"
};

static
{
Skript.registerEvent("On Vote Received", SimpleEvent.class, VoteReceivedEvent.class, PATTERNS);
Skript.registerEvent("On Votifier Vote", SimpleEvent.class, VotifierEvent.class, PATTERNS);

EventValues.registerEventValue
(
VoteReceivedEvent.class, Vote.class, new GoGetter<>(VoteReceivedEvent::getVote), 0
VotifierEvent.class, Vote.class, new GoGetter<>(VotifierEvent::getVote), 0
);
}

private final Vote vote;

public VoteReceivedEvent(Vote vote)
{
this.vote = vote;
}

public Vote getVote()
{
return vote;
}

@Override
public HandlerList getHandlers()
{
return HANDLERS;
}

public static HandlerList getHandlerList()
{
return HANDLERS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class VoteTimestampExpression extends SimplePropertyExpression<Vote, String>
{
public static final String PATTERN = "[received] [voter] time[(-| )]stamp";
public static final String PATTERN = "[(voter|sender)] time[(-| )]stamp";

static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class VoterIpAddressExpression extends SimplePropertyExpression<Vote, String>
{
public static final String PATTERN = "[received] [(voter|sender)] [ip(-| )]address";
public static final String PATTERN = "[(voter|sender)] [ip(-| )]address";

static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class VoterUsernameExpression extends SimplePropertyExpression<Vote, String>
{
public static final String PATTERN = "[voter] user[(-| )]name";
public static final String PATTERN = "[(voter|sender)] user[(-| )]name";

static
{
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/rezzedup/skriptvotifierhook/types/VoteType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.rezzedup.skriptvotifierhook.types;

import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import com.vexsoftware.votifier.model.Vote;

public class VoteType
{
static
{
Classes.registerClass
(
new ClassInfo<>(Vote.class, "vote")
.user("vote")
.name("Vote")
.description("A vote from votifier.")
.since("1.0.0")
.defaultExpression(new EventValueExpression<Vote>(Vote.class))
.parser(new Parser<Vote>()
{
@Override
public Vote parse(String s, ParseContext context)
{
return null;
}

@Override
public boolean canParse(ParseContext context)
{
return false;
}

@Override
public String toString(Vote vote, int i)
{
return vote.toString();
}

@Override
public String toVariableNameString(Vote vote)
{
return toString(vote, 0);
}

@Override
public String getVariableNamePattern()
{
return ".+";
}
})
);
}
}

0 comments on commit 16ac1c5

Please sign in to comment.